class Solution {
    public String addBinary(String a, String b) {
        int i = a.length() - 1;
        int j = b.length() - 1;
        int t = 0;
        StringBuilder result = new StringBuilder();
        while (i >=0 || j >= 0 || t != 0) {
            if (i >= 0) t += a.charAt(i--) - '0';
            if (j >= 0) t += b.charAt(j--) - '0';
            result.append((char)((char)(t % 2) + '0'));
            t /= 2;
        }
        return result.reverse().toString();
    }
}